package com.dmn.gcode.springchains.baseoperators;

import com.dmn.gcode.springchains.core.AbstractOperator;
import com.dmn.gcode.springchains.core.IChainMaster;
import com.dmn.gcode.springchains.core.IOperator;
import com.dmn.gcode.springchains.core.In;

/**
 * date 17.01.11
 *
 * @author dvponomarev
 * @version 1.0
 */
public class IfOperator extends AbstractOperator {
    //in
    private In<Boolean> condition;
    private IOperator falseOperator;
    private IOperator trueOperator;

    public void execute(IChainMaster chainMaster) throws Throwable {
        if (condition.get()) {
            if (trueOperator != null) {
                chainMaster.execute(trueOperator);
            }
        } else {
            if (falseOperator != null) {
                chainMaster.execute(falseOperator);
            }
        }
    }

    public void setCondition(In<Boolean> condition) {
        this.condition = condition;
    }

    /**
     * May not be set.
     */
    public void setFalseOperator(IOperator falseOperator) {
        this.falseOperator = falseOperator;
    }

    /**
     * May not be set.
     */
    public void setTrueOperator(IOperator trueOperator) {
        this.trueOperator = trueOperator;
    }
}
